#ifndef __Graphics_H__
#define __Graphics_H__

// -------- Include Headers --------
#include <d3d9.h>
#include <d3dX9.h>
#include <map>

#include "Player.h"
#include "Tile.h"
#include "Map.h"

class CGraphics
{
    // key : texture name
    typedef std::map<std::string, LPDIRECT3DTEXTURE9>               vTextureMap;
    typedef std::map<std::string, LPDIRECT3DTEXTURE9>::iterator     vTextureMapItor;

    // key : tile index, value : tile
    typedef std::map<UINT, CTile>::iterator                     vMapItor;
    typedef std::pair<UINT, CTile>                              vMapInsert;

public:

    HWND                m_hWnd;

    LPDIRECT3D9         m_pD3D;

    LPDIRECT3DDEVICE9   m_pD3DDevice;

    LPD3DXSPRITE        m_pSprite;

    LPDIRECT3DTEXTURE9  m_pTexture;

    LPDIRECT3DTEXTURE9  m_pTextureTemp;

    vTextureMap         m_vTextureMap;

    D3DDISPLAYMODE      m_d3ddm;
    
    INT                 m_TextureIndex;

    // player class

    INT                 m_PlayerTileIndex;

    INT                 m_PlayerPreDir;

    INT                 m_PlayerCurDir;

    RECT                m_Rect;

    const RECT*         m_pRect;

    enum
    {
        DIR_UP = 5,
        DIR_DOWN = 1,
        DIR_LEFT = 3,
        DIR_RIGHT = 7
    };

public:

    CGraphics();

    ~CGraphics();

    void                InitD3DD(HWND);

    void                ReleaseD3D();

    void                InitMap(UINT TileWidth, UINT TileHeight);

    void                DrawMap();

    void                DrawWall();

    void                LoadImage(std::string _pSrcFile);

    void                DrawPlayer();

    LPDIRECT3D9         GetDirect3DCOM();                   // get the d3d ptr

    LPDIRECT3DDEVICE9   GetDeviceCOM();                     // get the d3d device ptr

    LPD3DXSPRITE        GetSpriteCOM();                     // get the sprite ptr

    BOOL                Display();                          // displays the created frame

    BOOL                BeginScene();                       // begins the 3D scene

    BOOL                EndScene();                         // ends the 3D scene

    BOOL                ClearDisplay(D3DCOLOR Color = D3DCOLOR_XRGB(255, 255, 255));       // clear the window to a deep gray

    BOOL                BeginSprite();                      // begins the sprite

    BOOL                EndSprite();                        // ends the sprite
};

#endif
